<?php

$siteID = "";

$titleID = "";

if(@$_GET['siteid']){
	
	$siteID = $_GET['siteid'];
}

if(@$_GET['titleid']){
	
	$titleID = $_GET['titleid'];
}

$statusflag = false;

if(@$_GET["xmlstatusmode"]){
	
	$statusflag = true;

	switch($_GET["xmlstatusmode"]){
		
		case "locking":
			
			$sql = "UPDATE ".$PROJECT_DB_TABLES["tags"]." SET x_status=2,x_lockedby = '".$USER -> getID()."',x_modifiedby = '".$USER -> getID()."',x_modified = '".date("Y-m-d H:i:s",time())."' WHERE x_id = '".$siteID."'";//sql script to lock the 
			
			executeSQLQuery($sql);
			
			break;
			
		case "unlocking":
		
			$sql = "UPDATE ".$PROJECT_DB_TABLES["tags"]." SET x_status=1,x_lockedby = '',x_modifiedby = '".$USER -> getID()."',x_modified = '".date("Y-m-d H:i:s",time())."' WHERE x_id = '".$siteID."'";
			
			executeSQLQuery($sql);
			
			break;
		
		case "submitting":
		
			$sql = "UPDATE ".$PROJECT_DB_TABLES["tags"]." SET x_status=3,x_modifiedby = '".$USER -> getID()."',x_modified = '".date("Y-m-d H:i:s",time())."' WHERE x_id = '".$siteID."'";
			
			executeSQLQuery($sql);
			
			break;
		
		case "approving":
		
			$sql = "UPDATE ".$PROJECT_DB_TABLES["tags"]." SET x_status=4,x_modifiedby = '".$USER -> getID()."',x_modified = '".date("Y-m-d H:i:s",time())."' WHERE x_id = '".$siteID."'";
			
			executeSQLQuery($sql);

			break;
		
		case "redoing":
		
			$sql = "UPDATE ".$PROJECT_DB_TABLES["tags"]." SET x_status=2,x_modifiedby = '".$USER -> getID()."',x_modified = '".date("Y-m-d H:i:s",time())."' WHERE x_id = '".$siteID."'";
			
			executeSQLQuery($sql);
			
			break;
			
		case "unapproving":
		
			$sql = "UPDATE ".$PROJECT_DB_TABLES["tags"]." SET x_status=3,x_modifiedby = '".$USER -> getID()."',x_modified = '".date("Y-m-d H:i:s",time())."' WHERE x_id = '".$siteID."'";
			
			executeSQLQuery($sql);
			
			break;		
	}
	
	//LoadXML();
	
}

if($statusflag){
	
	LoadXML();
	
	refreshPageSiteTree();
}
else{

	$currentTag = $XML1 -> getTag($siteID);
	
	$currentTagStatus = $currentTag -> getStatus();
	
	addContent("<b>Current Status:</b>".$currentTagStatus."");
	
	$flagDeveloper = false;//flag to check whether the current user is developer
	
	$flagAdministrator = false;//flag to check whether the current user is administrator
	
	$flagDeveloper = $USER -> IsNameInGroup("Developers");
	
	$flagAdministrator = $USER -> IsNameInGroup("Administrators");
	
	switch($currentTagStatus){
		
		case "Pending":
		
			if(!$flagDeveloper && !$flagAdministrator){
			
				addContent ("&nbsp;".htmlChangePageStatus('locking',$siteID,$titleID,$currentTag->getData('x_section')));//<a href=\"javascript:void(0)\" onclick=\"onclick_changeTagStatus('locking','".$siteID."','".$titleID."','".$currentTag->getData('x_section')."')\">Lock</a>".
			}
			
			htmlPageComment($currentTag,false);	
				
			htmlTitleComment($currentTag,false,$titleID);
			
			htmlInteraction($currentTag,1);
		
			break;
			
		case "Locked":
		
			if(!$flagDeveloper && !$flagAdministrator){
				
				if($XML1 -> getPageLocker($currentTag->getID()) == $USER -> getID()){
					
					addContent ("&nbsp;".htmlChangePageStatus('unlocking',$siteID,$titleID,$currentTag->getData('x_section'))."&nbsp;");//<a href=\"javascript:void(0)\" onclick=\"onclick_changeTagStatus('unlocking','".$siteID."','".$titleID."','".$currentTag->getData('x_section')."')\">Unlock</a>
					
					addContent ("&nbsp;".htmlChangePageStatus('submitting',$siteID,$titleID,$currentTag->getData('x_section')));//<a href=\"javascript:void(0)\" onclick=\"onclick_changeTagStatus('submitting','".$siteID."','".$titleID."','".$currentTag->getData('x_section')."')\">Submit</a>
					
					htmlPageComment($currentTag,true);
					
					htmlTitleComment($currentTag,true,$titleID);
					
					htmlInteraction($currentTag,2);
				}
				else{
					
					addContent ("<br/><b>Current Page is locked by :</b>".$currentTag->getData("x_lockedby"));
					
					htmlPageComment($currentTag,false);
					
					htmlTitleComment($currentTag,false,$titleID);
					
					htmlInteraction($currentTag,1);
				}
		
			}
			else{
				
				addContent (htmlChangePageStatus('unlocking',$siteID,$titleID,$currentTag->getData('x_section')));//<a href=\"javascript:void(0)\" onclick=\"onclick_changeTagStatus('unlocking','".$siteID."','".$titleID."','".$currentTag->getData('x_section')."')\">Unlock</a>
				
				htmlPageComment($currentTag,false);
				
				htmlTitleComment($currentTag,false,$titleID);
				
				htmlInteraction($currentTag,1);
			}
			
			break;
			
		case "Unapproved":
		
			if($flagDeveloper || $flagAdministrator){
					
				addContent ("&nbsp;".htmlChangePageStatus('redoing',$siteID,$titleID,$currentTag->getData('x_section'))."&nbsp;&nbsp;");//<a href=\"javascript:void(0)\" onclick=\"onclick_changeTagStatus('redoing','".$siteID."','".$titleID."','".$currentTag->getData('x_section')."')\">Redo</a>
				
				addContent (htmlChangePageStatus('approving',$siteID,$titleID,$currentTag->getData('x_section')));//<a href=\"javascript:void(0)\" onclick=\"onclick_changeTagStatus('approving','".$siteID."','".$titleID."','".$currentTag->getData('x_section')."')\">Approve</a>
				
				htmlPageComment($currentTag,true);
				
				htmlTitleComment($currentTag,true,$titleID);
				
				htmlInteraction($currentTag,2);
		
			}
			else{
				
				htmlPageComment($currentTag,false);
				
				htmlTitleComment($currentTag,false,$titleID);
				
				htmlInteraction($currentTag,1);
			}
			
			break;
			
		case "Approved":
			
			if($flagDeveloper || $flagAdministrator){//if the current user is administrator or developer
				
				addContent ("&nbsp;".htmlChangePageStatus('unapproving',$siteID,$titleID,$currentTag->getData('x_section')));//<a href=\"javascript:void(0)\" onclick=\"onclick_changeTagStatus('unapproving','".$siteID."','".$titleID."','".$currentTag->getData('x_section')."')\">Unapprove</a>
				
				htmlPageComment($currentTag,false);
		
				htmlTitleComment($currentTag,false,$titleID);
				
				htmlInteraction($currentTag,3);
			}
			else {//if current user is not administrator nor developer
				
				htmlInteraction($currentTag,1);
			}
		
			break;
	}
	
	if($USER -> IsNameInGroup("Developers")){
		
		
	}
	else if($USER -> IsNameInGroup("Administrators")){
		
	}
	else{
		
	
	}
}

?>